package com.svmc.app.task.view;

import com.svmc.app.task.activity.R;
import com.svmc.app.task.adapter.DbAdapter;
import com.svmc.app.task.alarm.MyAlarmManager;
import com.svmc.app.task.model.TaskModel;
import com.svmc.app.task.utils.CommonDefine;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class DialogConfirm extends Activity implements OnClickListener,CommonDefine {
	TextView lb_task, note, timefinish;
	ImageView btn_okie, btn_cancel;
	TextView txt_message;
	TaskModel taskmodel;
	int id;
	int idalarm;
	DbAdapter db;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		this.getWindow().setBackgroundDrawable(
				new ColorDrawable(Color.argb(0, 255, 255, 255)));
		setContentView(R.layout.dialog_confirm);
		lb_task =(TextView)findViewById(R.id.dialogconfirm_txt_lbtask);
		lb_task.setText(getString(R.string.dialog_confirm_label));
		txt_message =(TextView)findViewById(R.id.dialogconfirm_txt_message);
		txt_message.setText(getString(R.string.dialog_confirm_message));
		btn_okie =(ImageView)findViewById(R.id.dialogconfirm_img_okie);
		btn_cancel=(ImageView)findViewById(R.id.dialogconfirm_img_cancel);
		btn_okie.setOnClickListener(this);
		btn_cancel.setOnClickListener(this);
        db = new DbAdapter(this);
		Bundle bundle = getIntent().getExtras();
		id = bundle.getInt("id_task");
		idalarm= bundle.getInt("id_alarm");
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.dialogconfirm_img_cancel:
			finish();
			break;
		case R.id.dialogconfirm_img_okie:
			int indexrow = db.deleteTaskByID(id);
			if(indexrow>0){
				MyAlarmManager myalarm = new MyAlarmManager(this);
				myalarm.cancelAlarm(idalarm);
				finish();
			}
			break;
		default:
			break;
		}
		
	}
	

}
